<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Analyze PDF document</title>
</head>
<body>
<h3>Analyze PDF document</h3>
Click on the button to analyze the PDF document.
</p>
<div id="status"></div>
</p>
<div id="result" style="white-space: pre-wrap;"></div>
</p>
<button id="analyze">Analyze</button>
<button id="clear" disabled>Clear</button>

<script>
    document.getElementById('analyze').addEventListener('click', function () {
        document.getElementById('status').textContent = 'Working...';
        fetch('/analyze-pdf-document')
            .then(response => response.text())
            .then(data => {
                document.getElementById('status').textContent = '';
                document.getElementById('result').innerHTML = data;
                document.getElementById('clear').disabled = false;
            })
            .catch(error => {
                console.log(error);
                document.getElementById('status').textContent = 'Failed! Have you started the mock mail container? ';
            });
    });

    document.getElementById('clear').addEventListener('click', function () {
        document.getElementById('result').innerHTML = '';
        this.disabled = true;
    });
</script>
</body>
</html>
